package com.wuzf.controller;


import com.netflix.discovery.converters.Auto;
import com.wuzf.common.entity.CommonResult;
import com.wuzf.common.entity.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import com.wuzf.service.PaymentService;

@RestController
public class PaymentController {


    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private int port;


    @PostMapping("/payment/create")
    public CommonResult create(@RequestBody Payment payment) {
        int result = paymentService.createPayment(payment);
        if (result > 0) {
            return new CommonResult(200, "新增成功，" + "端口号：" + port, payment);
        } else {
            return new CommonResult(444, "新增失败，" + "端口号：" + port);
        }
    }


    @GetMapping("/payment/get/{id}")
    public CommonResult findById(@PathVariable long id) {
        Payment payment = paymentService.getPaymentById(id);
        if (payment == null) {
            return new CommonResult(444, "找不到数据，" + "端口号：" + port);
        } else {
            return new CommonResult(200, "获取成功，" + "端口号：" + port, payment);
        }
    }
}
